Quality control and filtering results from cellranger

Sample info and environment setup

PRJNA732205

setwd("/media/jacopo/Elements/re_align/MM/PRJNA732205/SAMN19314101/SRR14629343/")
# Load the libraries (from Sarah script + biomart)
library(tidyverse) # packages for data wrangling, visualization etc
library(Seurat) # scRNA-Seq analysis package
library(clustree) # plot of clustering tree 
library(ggsignif) # Enrich your 'ggplots' with group-wise comparisons
library(clusterProfiler) #The package implements methods to analyze and visualize functional profiles of gene and gene clusters.
library(org.Hs.eg.db) # Human annotation package neede for clusterProfiler
library(ggrepel) # extra geoms for ggplo2
library(patchwork) #multiplots
library(reticulate)

Load and process cellranger data

Load and do the QC for the cellranger data

#list.files(".")
dat <- Read10X(data.dir ="./out/counts_filtered/")
dat <- CreateSeuratObject(dat) # Create the seurat object from the 10x data
kb.initial <- dat@assays[["RNA"]]@counts@Dim[[2]]
cat("Initial number of cells:", kb.initial, 
    "\nNumber of genes:",  dat@assays[["RNA"]]@counts@Dim[[1]])
## Initial number of cells: 3474 
## Number of genes: 36601

Quality Control

Empty cells were already filtered, check for % mt RNA and death markers:

# first calculate the mitochondrial percentage for each cell
dat$percent_mt <- PercentageFeatureSet(dat, pattern="^MT.")
# make violin plots
mt_rna = 15
max_counts = 30000



# Check some feature-feature relationships
# % mt RNA vs n Counts, n Features vs n Counts
# Check some feature-feature relationships
# % mt RNA vs n Counts, n Features vs n Counts
VlnPlot(dat, features = c("nCount_RNA", "nFeature_RNA", "percent_mt"))  + geom_hline(yintercept=mt_rna, linetype = "dotted")

plot1 <- FeatureScatter(dat, feature1 = "nCount_RNA", feature2 = "percent_mt")
plot1 <- plot1 + geom_hline(yintercept=mt_rna, linetype = "dotted")
plot2 <- FeatureScatter(dat, feature1 = "nCount_RNA", feature2 = "nFeature_RNA")
plot2 <- plot2 + geom_vline(xintercept = max_counts, linetype = "dotted")
plot1 

plot2

##  cells retained by mt RNA content ( 15 %): 3212 
##  percentage of retained cells: 92.46 %
## cells retained by counts ( 30000 ): 3208 
##  percentage of retained cells: 92.34 %

Check the distribution of the cells with low counts and control death markers:

min_counts = 350


hist(dat@meta.data$nCount_RNA, breaks = 100, xlab = "Counts")

hist(dat@meta.data$nCount_RNA, breaks = 1000, xlab = "Counts", xlim = c(0,5000))

hist(dat@meta.data$nCount_RNA, breaks = 10000, xlab = "Counts", xlim = c(0,1000))
abline(v=min_counts, col="red", lty = 3)

The evident peak of cells with < 200 counts could contain dying cells.

# Subset the dataset to focus only on those cells with low counts
dat.lowcount <- subset(dat, subset = nCount_RNA < min_counts)

# Get the mean of the counts for each gene and sort them decreasing
meanCounts <- rowMeans(GetAssayData(object = dat.lowcount, slot = 'counts'))
meanCounts <- sort(meanCounts, decreasing = T)

# A boxplot can help to observe the distribution of the means
#boxplot(meanCounts)

# Print the most highly expressed genes
head(meanCounts, 30)
##       IGKC      IGHG4     MALAT1        B2M      RPLP1      RPS18      RPL10 
## 67.4994536  9.2524590  7.6480874  3.1967213  2.0644809  1.9693989  1.8043716 
##       SSR4      RPS14      RPL41      RPL32      RPL35      RPS27      RPL13 
##  1.5431694  1.3081967  1.1934426  1.1344262  1.1213115  1.0743169  1.0524590 
##      RPL34      RPS19     RPL13A       MZB1     RPL35A       RPS6      RPLP2 
##  0.9989071  0.9868852  0.9770492  0.9748634  0.9300546  0.9278689  0.8852459 
##      RPS17     RPL27A      RPS15     EEF1A1      RPL26      RPL17      RPS23 
##  0.8284153  0.8207650  0.8163934  0.8142077  0.7857923  0.7803279  0.7781421 
##     RPL18A        FTL 
##  0.7770492  0.7748634
## cells retained by counts ( 350 ): 2292 
##  percentage of retained cells: 65.98 %

dir.create("result")
saveRDS(dat, file = "./result/SAMN19314101_clean_QC.Rds")

Feature selection

#Normalize
dat <- NormalizeData(dat)
# Find the first 4000 variabe features
dat <- FindVariableFeatures(dat, selection.method = "vst", nfeatures = 4000)

Data scaling

Set mean expression to 0 and variance across 1 to avoid highly expressed genes drive the forwarding analyses. Since negative expression is meaningless, scaled data are useful only for UMAP and clustering

# scale data, the scaled data are saved in:
# dat[["RNA"]]@scale.data

all.genes <- rownames(dat)

dat <- ScaleData(dat, vars.to.regress = c("percent_mt","nCount_RNA"))

Dimensionality reduction

dat <- RunPCA(dat, features = VariableFeatures(object = dat), verbose = F, seed.use = 1)
print(dat[["pca"]], dims = 1:5, nfeatures = 5)
## PC_ 1 
## Positive:  RPS18, RPL10, RPS8, RPS20, RPL32 
## Negative:  HBA1, HBA2, HBB, ALAS2, HBM 
## PC_ 2 
## Positive:  RPS18, RPS27, RPL13, RPL32, RPS12 
## Negative:  LMAN2, HLA-B, HLA-DOB, PDIA6, B2M 
## PC_ 3 
## Positive:  HBA1, HBA2, HBB, RPL10, RPLP1 
## Negative:  PPP1R15A, IER2, JUN, HIST1H2BG, IER3 
## PC_ 4 
## Positive:  MZB1, ITM2C, IGHG2, CYBA, SSR4 
## Negative:  HBA1, HBB, HBA2, STMN1, PCLAF 
## PC_ 5 
## Positive:  IGHG2, IGHV1-24, PCLAF, DDX17, ODC1 
## Negative:  B2M, Z93241.1, NFKBIA, AL021155.5, HIST1H2BG

UMAP

UMAP is a graph-based method of clustering. The first step in this process is to construct a KNN graph based on the euclidean distance in PCA space:

dat <- FindNeighbors(dat, dims = 1:20)

The graph now can be used as input for the function runUMAP()

dat <- RunUMAP(dat, dims = 1:20, seed.use = 1)
DimPlot(dat, reduction = 'umap', seed = 1)

Final plots:

## QC metrics

## markers